﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace formworks.DBO.Core
{
    /// <summary>
    /// microsoft sql server 的特殊实现
    /// 继承自 DataBaseSys实现的方法
    /// </summary>
    public class DBMSSQL : DBSessionFactory
    {
        
        public DBMSSQL(string connectionString) : base(connectionString)
        {
           
            //this.connectionString = connectionString;
            
        }

        public DBMSSQL(SqlConnection connection) : base(connection)
        {
            //this.connection = connection;
        }

        #region IDBSessionFactory 成员


        public override DBSession openSession()
        {
            try
            {
                //判断连接是否建立
                if (null == connection)
                {
                    //没有建立就建立连接对象
                    connection = new SqlConnection(connectionString);
                }

                //创建一个数据库对话对象
                DBSession dbSession = new DBSession(connection);
                return dbSession;
            }
            catch (System.Exception ex)
            {
                if (null != connection)
                {
                    if (connection.State != ConnectionState.Closed)
                    {
                        connection.Close();
                    }//
                }//end con
                throw ex;
            }
        }

        #endregion

        
    }
}
